
#ifndef __T_CONSOLE_H
#define __T_CONSOLE_H

#include <stdio.h>
#include "common/config.h"
#include "uv.h"

#define CONSOLE_CMD_ROOT "/usr/bin"
#define CONSOLE_HOME "/home/Tim"

#define console_error(format, args...)                       \
	do                                                       \
	{                                                        \
		printf("\33[31m");                                   \
		printf("ERROR <%s(),%d>##", __FUNCTION__, __LINE__); \
		perror("");                                          \
		printf(format, ##args);                              \
		printf("\33[0m");                                    \
	} while (0)

#define console_warn(format, args...)                       \
	do                                                      \
	{                                                       \
		printf("\33[33m");                                  \
		printf("WARN <%s(),%d>##", __FUNCTION__, __LINE__); \
		printf(format, ##args);                             \
		printf("\33[0m");                                   \
	} while (0)

#define console_msg_declare(module) static int console_msg_level_##module = 0
#define console_msg_level(module, level, format, args...)      \
	do                                                         \
	{                                                          \
		if (level >= console_msg_level_##module)               \
		{                                                      \
			printf("\33[32m");                                 \
			printf("MSG <%s(),%d>##", __FUNCTION__, __LINE__); \
			printf(format, ##args);                            \
			printf("\33[0m");                                  \
		}                                                      \
	} while (0)
#define console_msg(module, format, args...) console_msg_level(module, 0, format, ##args)
#define console_level(module, level) console_msg_level_##module = level

#define console_here                                       \
	do                                                     \
	{                                                      \
		printf("Debug,%s(),%d\n", __FUNCTION__, __LINE__); \
	} while (0)
#define CONSOLE_UDP_PORT (40001)
#define error_null_ptr() console_error("null ptr\n")

// #define CONSOLE_CMD_ARGS_NUM (16)
// typedef struct _CONSOLE_CMD_PARAM_S
// {
// 	char abyCmd[32];
// 	int nArgsNum;
// 	char abyArgs[CONSOLE_CMD_ARGS_NUM][32];
// } CONSOLE_CMD_PARAM_S;

typedef int (*CONSOLE_CMD_CB)(CONSOLE_CMD_PARAM_S *, char *);

#define CONSOLE_CMD_MAX (256)
typedef struct _CONSOLE_CMD_NODE_S
{
	char abyCmd[32];
	CONSOLE_CMD_CB cb;
	int nUsed;
} CONSOLE_CMD_NODE_S;

static inline void printHex(char *pBuf, int nLen)
{
	int i;
	unsigned char *pBuf2 = (unsigned char *)pBuf;
	//printf("\n");
	for (i = 0; i < nLen; i++)
	{
		printf("%02x ", pBuf2[i]);
	}
	printf("\n");
}

int Console_Loop(uv_work_t *handle);
int Console_CmdAdd(char *pCmd, CONSOLE_CMD_CB cb);
int Console_CmdDel(char *pCmd);
int Console_Init(void);
int Console_DeInit(void);
#endif